'''
Created on Feb 28, 2009

@author: leonardobessa
'''
from google.appengine.ext import db

class Room(db.Model):
  number = db.IntegerProperty(required=True)
  single_beds = db.IntegerProperty(required=True)
  double_beds = db.IntegerProperty(required=True)
  sex = db.StringProperty(required=True, choices=set(["M", "F", "C","Any"]))

  def capacity(self):
    return self.single_beds + 2 * self.double_beds;

  def avaiableBeds(self):
    return int(self.capacity() - self.people().count()) ;

  def people(self):
    people = Person.all()
    people.filter("room =", self)
    return people

  def isFull(self):
    return self.avaiableBeds() == 0;

  def getGenre(self):
    genre = ""
    if self.sex == 'M' : genre = 'homens'
    if self.sex == 'F' : genre = 'mulheres'
    if self.sex == 'C' : genre = 'casados'
    if self.sex == 'Any' : genre = 'livre'
    return genre

class Person(db.Model):
  name = db.StringProperty(required=True)
  email_address = db.EmailProperty(required=True)
  sex = db.StringProperty(required=True, choices=set(["M", "F","C"]))
  password = db.StringProperty(required=True)
  room = db.ReferenceProperty(Room)
